using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using Sirenix.OdinInspector;
using System;


public class FontLocalizer : Localizer
{

    Text text;

    public static Func<string, Font> onGetFont;

    public static Font GetFont(string language)
    {
        if(onGetFont == null)
        {
            throw new Exception("[FontLocalizer] onGetFont not set yet");
        }
        var font = onGetFont.Invoke(language);
        return font;
    }

    void Awake()
    {
        var text = this.GetComponent<Text>();
        this.text = text;

    }


    bool HasTextComponent
    {
        get
        {
            if (text != null)
            {
                return true;
            }
            return false;
        }
    }
    protected override void Refresh()
    {
        var hasTextComponent = this.HasTextComponent;
        if (!hasTextComponent)
        {
            return;
        }

        if (this.text == null)
        {
            return;
        }

        var language = LanguageManager.Stuff.Language;
        var font = GetFont(language);
        this.text.font = font;
    }

}
